import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { TSite } from 'src/entities/site.entity';

export class SiteRepository {
  constructor(
    @InjectRepository(TSite)
    private siteRepository: Repository<TSite>,
  ) {}

  // 查询
  querySiteListRepository() {
    return this.siteRepository.find({
      where: {
        delFlag: 0,
      },
    });
  }

  // 新增
  addSiteRepository(site: TSite) {
    const siteDb = this.siteRepository.create(site);
    return this.siteRepository.save(siteDb);
  }

  // 修改
  updateSiteRepository(id: number, site: TSite) {
    return this.siteRepository.update(id, site);
  }

  // 删除
  deleteSiteRepository(id: number) {
    return this.siteRepository.update(id, { delFlag: 1 });
  }
}
